package gttp.nspa.client.adm.place;

import gttp.nspa.shared.om.Customer;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

public class CustomerPlace extends Place {

    public static class Tokenizer implements PlaceTokenizer<CustomerPlace> {

        public CustomerPlace getPlace(String token) {
            Long therapistId;
            try {
                therapistId = new Long(token);
            } catch (NumberFormatException e) {
                therapistId = null;
            }
            return new CustomerPlace(therapistId);
        }

        public String getToken(CustomerPlace place) {
            if (place.custId != null) {
                return place.custId.toString();
            } else if (place.cust != null) {
                return place.cust.getId().toString();
            }
            return "";
        }

    }

    public final Long     custId;
    public final Customer cust;

    public CustomerPlace() {
        custId = null;
        cust = null;
    }

    public CustomerPlace(Long id) {
        custId = id;
        cust = null;
    }

    public CustomerPlace(Customer c) {
        custId = null;
        cust = c;
    }
}
